package com.yvtian.utils;

public class StringHelper{

    public static String getObjectValue(Object obj){
        return obj == null ? "" : obj.toString();
    }

    public static boolean isEmpty(String var){
        return (var == null || "".equals(var));
    }

    public static boolean isNotEmpty(String var){
        return !isEmpty(var);
    }

    /**
     * 截取字符串
     *
     * @param str   字符串
     * @param start 开始
     * @param end   结束
     * @return 结果
     */
    public static String substring(String str,int start,int end){
        if (str == null) {
            return "";
        }

        if (end < 0) {
            end = str.length() + end;
        }
        if (start < 0) {
            start = str.length() + start;
        }

        if (end > str.length()) {
            end = str.length();
        }

        if (start > end) {
            return "";
        }

        if (start < 0) {
            start = 0;
        }
        if (end < 0) {
            end = 0;
        }
        return str.substring(start, end);
    }
}
